#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int T, n, ans, a[N];
bool f[N];

int cal() {
    int red = -1, blue = -1, sum = 0;
    for (int i = 1; i <= n; i++)
        if (f[i] == 0)
            if (a[i] == red)sum += red;
            else red = a[i];
        else
            if (a[i] == blue)sum += blue;
            else blue = a[i];
    return sum;
}

void dfs(int depth) {
    if (depth > n) {
        ans = max(ans, cal());
        return ;
    }
    f[depth] = 1;
    dfs(depth + 1);
    f[depth] = 0;
    dfs(depth + 1);
    return ;
}
int main() {
#ifndef Local
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
#endif
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%d", a + i);
        if (n <= 20) {
            ans = -1;
            dfs(1);
            printf("%d\n", ans);
        }

    }
    return 0;
}
